<template>
  <page-header-wrapper>
    <page-tab-list>
      <div class="table-page-search-box">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="8" :sm="24">
              <a-form-item label="举报人姓名">
                <a-input placeholder="请输入举报人姓名" v-model="queryParam.name" allowClear></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="举报标题">
                <a-input placeholder="请输入举报标题" v-model="queryParam.title" allowClear></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="详情ID">
                <a-input placeholder="请输入ID" v-model="queryParam.report_id" allowClear></a-input>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row :gutter="24">
            <a-col :md="8" :sm="24">
              <a-form-item label="举报类型">
                <a-select placeholder="请选择" v-model="queryParam.type" allowClear>
                  <a-select-option value="0"> 默认投诉 </a-select-option>
                  <a-select-option value="1"> 涉及色情暴力 </a-select-option>
                  <a-select-option value="2"> 涉及欺诈造假 </a-select-option>
                  <a-select-option value="3"> 违禁信息 </a-select-option>
                  <a-select-option value="4"> 感觉被冒犯或歧视 </a-select-option>
                  <a-select-option value="5"> 涉及侵权 </a-select-option>
                  <a-select-option value="6"> 其他 </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="">
                <a-button type="primary" @click="getList()">查询</a-button>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </page-tab-list>
    <a-card :border="false">
      <div class="table-operator" style="display: flex; justify-content: space-between">
        <a-radio-group v-model="queryParam.status" @change="getList()">
          <a-radio-button value="0"> 未处理 </a-radio-button>
          <a-radio-button value="1"> 已处理 </a-radio-button>
        </a-radio-group>
        <a-dropdown>
          <a-menu slot="overlay">
            <a-menu-item @click="handleAll('remove', 1)">批量下架</a-menu-item>
            <a-menu-item @click="handleAll('remove', 2)">批量删除</a-menu-item>
          </a-menu>
          <a-button> 批量操作 </a-button>
        </a-dropdown>
      </div>

      <a-table
        :rowKey="
          (r, i) => {
            return r.report_id
          }
        "
        :rowSelection="{ selectedRowKeys: this.selectedRowKeys, onChange: this.onSelectChange }"
        size="default"
        :columns="columns"
        :data-source="list"
        :scroll="{ x: 'max-content' }"
        :pagination="{
          page: this.queryParam.page,
          total: this.totalCount,
          showSizeChanger: false,
          onChange: this.tablePageChange
        }"
      >
        <div slot="content" slot-scope="text, record">
          <div class="content">
            <div class="img">
              <a-avatar shape="square" :size="48" icon="user" :src="record.report_avatar" />
            </div>

            <div class="txt">
              <h3>{{ record.report_user_name }}</h3>
              <p>id: {{ record.report_user_id }}</p>
            </div>
          </div>
        </div>

        <span slot="report_created_at" slot-scope="text, record">
          {{
            record.report_created_at > 0 ? $moment(record.report_created_at * 1000).format('YYYY-MM-DD HH:mm:ss') : '-'
          }}
        </span>

        <span slot="action" slot-scope="text, record">
          <a-button type="link" size="small" @click="see(record)">查看</a-button>
          <a-divider type="vertical" />
          <a-dropdown v-if="record.report_status === '0'">
            <a-menu slot="overlay">
              <a-menu-item>
                <a href="javascript:;" @click="handleItem('remove', 1, record)">下架</a>
              </a-menu-item>
              <a-menu-item>
                <a href="javascript:;" @click="handleItem('remove', 2, record)">删除</a>
              </a-menu-item>
            </a-menu>
            <a class="ant-dropdown-link"> 更多 <a-icon type="down" /> </a>
          </a-dropdown>
        </span>
      </a-table>

      <ContentDetails title="反馈详情" ref="pop" @cancel="item = null">
        <div class="popContent" v-if="item">
          <h1>{{ item.vl_title }}</h1>
          <p>{{ item.vl_content }}</p>

          <div class="img" v-if="String(item.vl_type) !== '1' && item.vl_pic_list.length">
            <img :src="e" alt="" v-for="(e, index) of item.vl_pic_list" :key="e" @click="seeImg(e)" />
          </div>
          <video v-if="String(item.vl_type) === '1'" :src="item.vl_video_url" controls></video>

          <div class="creatTime">
            举报时间：{{ $moment(item.report_created_at * 1000).format('YYYY-MM-DD HH:mm:ss') }}
          </div>

          <div class="creatTime">举报内容：{{ item.report_desc }}</div>

          <div class="creatTime">被举报人：{{ item.reported_name }}</div>
        </div>
      </ContentDetails>
      <ModalImg :previewImage="previewImage" ref="ModalImg"></ModalImg>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { videoGoodsReportList, videoGoodsHandleReport } from '@/api/videoClassify'

const columns = [
  {
    title: 'ID',
    dataIndex: 'report_id',
    width: 50
  },
  {
    title: '举报人信息',
    scopedSlots: {
      customRender: 'content'
    },
    width: 300
  },
  {
    title: '作品分类',
    dataIndex: 'cat_name',
    scopedSlots: {
      customRender: 'cat_name'
    }
  },
  {
    title: '举报作者',
    dataIndex: 'reported_name',
    scopedSlots: {
      customRender: 'reported_name'
    }
  },
  {
    title: '举报内容',
    dataIndex: 'report_desc',
    scopedSlots: {
      customRender: 'report_desc'
    },
    ellipsis: true,
    width: 300
  },
  {
    title: '举报时间',
    dataIndex: 'report_created_at',
    scopedSlots: {
      customRender: 'report_created_at'
    },
    sorter: (a, b) => a.report_created_at - b.report_created_at,
    width: 200
  },
  {
    title: '操作',
    scopedSlots: {
      customRender: 'action'
    }
  }
]

export default {
  components: {
    ContentDetails: () => import('@/components/tools/ContentDetail'),
    ModalImg: () => import('@/components/tools/ModalImg')
  },

  data() {
    return {
      columns,
      // 查询参数
      queryParam: {
        name: undefined,
        title: undefined,
        report_id: undefined,
        type: undefined,
        status: '0'
      },

      list: [],
      total: 0,
      pageNo: 1,
      pageSize: 10,
      selectedRowKeys: [],
      item: null,
      previewImage: undefined
    }
  },

  methods: {
    // 获取数据列表
    async getList(pageNo = 1) {
      const hide = this.$message.loading('加载中', 0)
      let { queryParam, pageSize } = this

      const res = await videoGoodsReportList({
        ...queryParam,
        pageSize,
        pageNo
      })
      if (res.code == 0) {
        this.selectedRowKeys = []
        let { totalCount, data } = res.data
        this.total = totalCount
        this.list = data
      }
      hide()
    },

    // 分页请求
    tablePageChange(e) {
      this.getList(e)
    },

    // 选中多行
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },

    // 下架(删除接口)
    changeStatus(type, id) {
      videoGoodsHandleReport({
        id,
        type
      }).then(res => {
        if (res.code !== 0) {
          this.$error({
            content: res.msg
          })
        } else {
          this.$message.success(res.msg)

          this.list = this.list.filter(el => id.indexOf(el.report_id) === -1)
          this.totalCount -= id.length

          if (!this.list.length) {
            this.getList()
          }

          this.selectedRowKeys = []
        }
      })
    },

    // 点击单个
    handleItem(type, status, item) {
      switch (type) {
        case 'remove':
          this.changeStatus(status, [item.report_id])
          break
      }
    },

    // 批量操作
    handleAll(type, status) {
      let { selectedRowKeys, list } = this
      if (!selectedRowKeys.length) {
        this.$message.error('请至少选择一条数据~')
        return
      }

      switch (type) {
        case 'remove':
          let ids

          if (status === 1) {
            ids = list
              .filter(el => {
                return selectedRowKeys.indexOf(el.report_id) !== -1 && el.report_status === '0'
              })
              .map(el => el.report_id)

            if (!ids.length) {
              this.$message.error('请选择符合条件的数据~')
              return
            }
          } else {
            ids = list.map(el => el.report_id)
          }

          this.changeStatus(status, ids)
          break
      }
    },

    see(item) {
      console.log('item,', item)
      this.$refs.pop.visible = true
      this.item = item
    }
  },

  mounted() {
    this.getList()
  }
}
</script>

<style lang="less" scoped>
.searchBox {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding: 8px 0 18px 0;
  /deep/ .ant-input-affix-wrapper {
    width: 220px;
    margin-right: 20px;
  }
  .select {
    display: flex;
    align-items: center;
    margin-right: 20px;
  }
}

.content {
  display: flex;
  align-items: center;
  height: 48px;
  max-width: 300px;
  overflow: hidden;

  .txt {
    margin-left: 16px;
    flex: 1;
    overflow: hidden;

    * {
      margin: 0;
      font-size: 14px;
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
    }

    h3 {
      color: rgba(0, 0, 0, 0.85);
    }

    p {
      color: rgba(0, 0, 0, 0.45);
    }
  }
}

.report_desc {
  width: 300px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.popContent {
  .creatTime {
    padding-bottom: 10px;
  }

  .img {
    img {
      margin: 0 10px 10px 0;
      width: 100px;
      height: 100px;
      cursor: pointer;
    }
  }

  video {
    width: 100%;
    height: 400px;
  }

  h1 {
    font-size: 18px;
  }
}

.popTitle {
  font-size: 16px;
}
</style>
